package com.zzl.study.sharding.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zzl.study.sharding.aop.annotation.HintInlineAlgorithm;
import com.zzl.study.sharding.domain.University;
import com.zzl.study.sharding.mapper.UniversityMapper;
import org.apache.shardingsphere.infra.hint.HintManager;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: zhangzl
 * @date: 2022/7/16 12:35
 * @version: 1.0
 * @description: Hint行表达式分片算法测试Service
 */
@Service
public class HintInlineAlgorithmTestService {

    @Autowired
    private UniversityMapper universityMapper;

    /**
     * 测试查询大学表：精准查询
     * 使用@HintInlineAlgorithm注解来制定Hint分片值
     */
    @HintInlineAlgorithm(logicTable = "t_university", hintValue = "zhejiang")
    public void testEqSelectUniversityWithHintInlineAlgorithm() {
        QueryWrapper<University> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", 1548145159806398466L);
        List<University> universities = universityMapper.selectList(queryWrapper);// 通过
        for (University university : universities) {
            System.out.println(university);
        }
    }

}
